package kr.hkit.powerjava.chapter08.work;
/* PROGRAMMING 6 BankAccount클래스에 송금 기능을 추가하라 */
public class BankAccountP {
	private String owner;					//예금주
	private int accountNumber;			//계좌번호
	private int balance;						//잔고
	private int amount;
	
	public BankAccountP(String owner, int accountNumber, int balance) {
		this.owner = owner;
		this.accountNumber = accountNumber;
		this.balance = balance;
	}
	public int setBalance(int amount){
		return balance -= amount;
	}
	public int getBalance(){
		return balance;
	}
	public int transfer(int amount, BankAccountP otherAccount){
		if(balance < amount || balance == 0){
			System.out.println("출금 불가 잔액 : " + balance);
			return -1;
		}else{
			balance -= amount;
			otherAccount.setBalance(amount+otherAccount.getBalance());
			return 1;		
		}			
	}
	@Override
	public String toString() {
		return "BankAccountP [owner=" + owner + ", accountNumber="
				+ accountNumber + ", balance=" + balance + "]";
	}
	
	public void deposit(int amount){ 	//입금
		balance += amount;
	}
	
	public int withdraw(int amount){	//출금
		if(balance < amount || balance == 0){
			System.out.println("출금 불가 잔액 : " + balance);
			return -1;							//잔고
		}else{
			balance -= amount;
			return amount;
		}
	}
}